#ifndef WIDGET_H
#define WIDGET_H

#include "common/baseresteditor.h"
#include <head/g_functionbase.h>
#include "addcategory.h"
#include "additem.h"
#include "m_fhs.h"

namespace Ui {
class Widget;
}

class Widget : public BaseRestEditor
{
    Q_OBJECT

public:
    explicit Widget(QWidget *parent = nullptr);
    ~Widget();

    void updateMenu();
    void customKeyEvent(QKeyEvent *event);
    void updateListView();
    void updateTableView();
    void onReceivedObject(const QJsonObject &object);

    void processCategory(const QJsonArray &array);
    void processDetail(const QJsonArray &array);

    void newCategory();
    void editCategory();
    void removeCategory();
    void newItem();
    void editItem();
    void removeItem();
    void delayUpdateView(int type);

    void onAddCategory(const QJsonObject &object);
    void onUpdateCategory(const QJsonArray &array);
    void onAddItem(const QJsonObject &object);
    void onUpdateItem(const QJsonArray &array);

    bool isListViewActive();
    bool isTableViewActive();

private slots:
    void on_listView_doubleClicked(const QModelIndex &index);

private:
    Ui::Widget *ui;

    QString selectCategory;
    QMap<QString,QStringList> metaProperties;
    QMap<QString,QStringList> metaColumns;
};

#endif // WIDGET_H
